******************************************************************
*Input: FinTech/rejected borrowers dataset
*Output: Stata graph with share of firms per industry
******************************************************************
clear all 

use "$output\rejected_agg_industries_modified.dta", clear

gen label = "Manufacturing" if industry == "C" 
replace label = "Construction and real estate" if industry == "FL"
replace label = "Wholesale and retail trade" if industry == "G"
replace label = "Transportation and storage" if industry == "H"
replace label = "Accomodation and food service activities" if industry == "I"
replace label = "Information and communication" if industry == "J"
replace label = "Professional, scientific and technical activities" if industry == "M"
replace label = "Administrative and support service activities" if industry == "N"
replace label = "Public sector" if industry == "public"

drop if label == ""
gen rejected = accepted == 0

keep industry rejected accepted
rename (rejected accepted) (rejected accepted)

collapse (sum) rejected accepted,by(industry)

sort industry
egen tot_acc = total(accepted)
egen tot_rej= total(rej)

replace rejected = rejected/tot_rej*100
replace accepted = accepted/tot_acc*100

label var rejected "Rejected FinTech borrowers"
label var accepted "Accepted FinTech borrowers"

egen industry_num = group(industry)
graph hbar accepted rejected , over(industry_num, gap(*1)  ///
relabel(1 "Manufacturing"  ///
2 "Construction & real estate" ///
3 "Wholesale & retail trade" ///
4 "Transportation & storage" ///
5 "Accomodation & food" ///
6 "Information & communication" ///
7 "Scientific & technical activities" ///
8 "Support services" ///
9 "Public sector" ///
) ) ///
graphregion(color(white)) blabel(bar, format(%8.1f) ) nolabel ///
 bar(1, bcolor(emerald)) bar(2, bcolor(gs10%40)  lcolor(black))  ///
legend( region(lcolor(white) ) label(1 "Fintech borrowers") label(2 "Rejected borrowers") cols(2) size(medium) ) ylabel(,nogrid labsize(medium))
graph export "$figures\industries_rejected.pdf", as(pdf) replace 
graph save "$figures\industries_rejected.gph", replace 
